package com.xlhj.boot.mapstruct.mapper;

import com.xlhj.boot.mapstruct.entity.SysUserInfo;
import com.xlhj.boot.mapstruct.vo.UserVo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

import java.time.LocalDateTime;

/**
 * @Author: caijliu
 * @Date: 19/11/2021 20:23
 * @Description TODO
 * @Vsersion: 0.0.1
 */
@Mapper
public interface SysUserInfoMapper {

    SysUserInfoMapper INFO_MAPPER = Mappers.getMapper(SysUserInfoMapper.class);

    @Mapping(target = "id", defaultValue = "1")
    @Mapping(target = "password", ignore = true)
    @Mapping(source = "phonenumber", target = "phone")
    @Mapping(source = "sex.value", target = "sex")
    @Mapping(target = "status", constant = "正常")
    @Mapping(target = "salary", numberFormat = "#.00")
    @Mapping(target = "createTime", dateFormat = "yyyy-MM-dd HH:mm:ss")
    @Mapping(source = "userInfo", target = "updateTime", qualifiedByName = "now")
    UserVo map(SysUserInfo userInfo);

    @Named("now")
    default LocalDateTime now(Object source) {
        return LocalDateTime.now();
    }
}
